home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / buffdemo.zip / BUFFUNPR.BAS < prev    next >
BASIC Source File  |  1986-05-12  |  9KB  |  221 lines

  1. 10000 'LISTING 2, BUFFUNPR.BAS
  2. 10050 '
  3. 10100 'This program unprotects protected BASIC programs
  4. 10150 '
  5. 10200 'Copyright, 1985  VERSION 1.30
  6. 10250 '
  7. 10300 'By:       Jim Pottkotter
  8. 10350 '          3015 Kirby M'Liss Cove
  9. 10400 '          Memphis, TN 38115
  10. 10450 '
  11. 10500 '          (901) 795-2238
  12. 10550 '
  13. 10600 '=====>  Initialize environment
  14. 10650 '
  15. 10700 SCREEN 0,1,0,0                     'Text mode
  16. 10750 WIDTH 80                           '80 columns
  17. 10800 COLOR 10,0,0                       'Bright green on black background
  18. 10850 CLS                                'Clear the screen
  19. 10900 DEF SEG                            'Set default segment
  20. 10950 ON ERROR GOTO 17750                'General error handling
  21. 11000 '
  22. 11050 '=====>  Initialize variables and constants
  23. 11100 '
  24. 11150 PROTECTED.FILE$ = ""               'Drive and name of protected file
  25. 11200 PROTECTED% = 0                     'Boolean - initially false
  26. 11250 THIS.PROGRAM$ = "BUFFUNPR.BAS"     'The name of this program
  27. 11300 UNPROTECT.FILE$ = "UNPRBYTE.IMG"   'File containing unprotected status
  28. 11350 FIRST.LINE$ = ""                   'First line from protected file
  29. 11400 IK$ = ""                           'INKEY$ value
  30. 11450 LOOP% = 0                          'Loop counter
  31. 11500 MESG$ = ""                         'Error message
  32. 11550 EXTENSION% = 0                     'Boolean - true means user entered
  33. 11600                                    'an extension on input file name
  34. 11650 '
  35. 11700 '=====>  If this program is protected, save an unprotected version
  36. 11750 '
  37. 11800 WHILE PEEK(1124) <> 0
  38. 11850   POKE 1124,0
  39. 11900   PRINT
  40. 11950   PRINT "Saving unprotected version of "; THIS.PROGRAM$;" ";
  41. 12000   PRINT "on default drive."
  42. 12050   SAVE THIS.PROGRAM$
  43. 12100 WEND
  44. 12150 '
  45. 12200 PROTECTED.FILE$ = ""
  46. 12250 WHILE PROTECTED.FILE$ = ""
  47. 12300   COLOR 10,0,0
  48. 12350   PRINT "BASIC files on current drive and path: ";
  49. 12400   COLOR 7,0,0
  50. 12450   FILES "*.BAS"
  51. 12500   COLOR 10,0,0
  52. 12550   PRINT "Enter drive and name of protected file."
  53. 12600   PRINT
  54. 12650   PRINT "Example:   B:PROTECTD.BAS "
  55. 12700   PRINT
  56. 12750   PRINT "The default file extension is .BAS  "
  57. 12800   PRINT
  58. 12850   PRINT "Enter END to end program."
  59. 12900   PRINT
  60. 12950   PRINT
  61. 13000   WHILE PROTECTED.FILE$ = ""
  62. 13050     LOCATE CSRLIN - 1, 1
  63. 13100     GOSUB 20550                                   'Get file name
  64. 13150     IF PROTECTED.FILE$ = "" THEN GOSUB 17350      'Buzz
  65. 13200     WHILE PROTECTED.FILE$ = "END"
  66. 13250       COLOR 15,0
  67. 13300       PRINT
  68. 13350       PRINT "Bye!"
  69. 13400       PRINT
  70. 13450       END
  71. 13500     WEND
  72. 13550   WEND
  73. 13600   EXTENSION% = 0
  74. 13650   FOR LOOP% = 1 TO LEN(PROTECTED.FILE$)
  75. 13700     IF MID$(PROTECTED.FILE$,LOOP%,1) = "." THEN EXTENSION% = -1
  76. 13750   NEXT
  77. 13800   IF NOT EXTENSION% THEN PROTECTED.FILE$ = PROTECTED.FILE$ + ".BAS"
  78. 13850 WEND
  79. 13900 '
  80. 13950 PRINT
  81. 14000 PRINT "Opening "; PROTECTED.FILE$
  82. 14050 PRINT
  83. 14100 OPEN "I", 1, PROTECTED.FILE$
  84. 14150 INPUT #1, FIRST.LINE$
  85. 14200 CLOSE #1
  86. 14250 PROTECTED% = (ASC(LEFT$(FIRST.LINE$,1)) = 254)
  87. 14300 WHILE NOT PROTECTED%                      'If first byte = 254, then file
  88. 14350                                           'is a protected BASIC program
  89. 14400     GOSUB 17350                           'Low warning buzz
  90. 14450     COLOR 15,0                     'Bright white on black background
  91. 14500     PRINT PROTECTED.FILE$; " is not a protected BASIC program."
  92. 14550     GOSUB 16800                           'Press any key
  93. 14600 WEND
  94. 14650 '
  95. 14700 PRINT "Creating "; UNPROTECT.FILE$; " on default drive."
  96. 14750 BSAVE UNPROTECT.FILE$, 1124, 1
  97. 14800 '
  98. 14850 '
  99. 14900 ON ERROR GOTO 0
  100. 14950 CLS                                       'Clear the screen
  101. 15000 BUFF.1$ = STRING$(5,13)                   '5 carriage returns
  102. 15050 GOSUB 19150                               'Load the keyboard buffer
  103. 15100 LOCATE 2,1                                'Put cursor at row 2, col 1
  104. 15150 '-----  The following print statements display statements that are
  105. 15200 '-----  executable in direct mode.  When the program ends, we will
  106. 15250 '-----  be in direct mode, and the five carriage returns we save in
  107. 15300 '-----  the keyboard buffer will execute the statements.
  108. 15350 '-----
  109. 15400 '-----  The statements do the following:
  110. 15450 '-----
  111. 15500 '-----       1.  LOAD the protected program
  112. 15550 '-----
  113. 15600 '-----       2.  BLOAD a byte of data that identifies the currently
  114. 15650 '-----           loaded program as unprotected.
  115. 15700 '-----
  116. 15750 '-----       3.  KILL the file used in step 2.
  117. 15800 '-----
  118. 15850 '-----       4.  SAVE the previously protected program in unprotected
  119. 15900 '-----           format.
  120. 15950 '-----
  121. 16000 '-----       5.  LIST the now unprotected program.
  122. 16050 '-----
  123. 16100 PRINT "LOAD";  CHR$(34); PROTECTED.FILE$
  124. 16150 PRINT
  125. 16200 PRINT "BLOAD"; CHR$(34); UNPROTECT.FILE$
  126. 16250 PRINT
  127. 16300 PRINT "KILL";  CHR$(34); UNPROTECT.FILE$
  128. 16350 PRINT
  129. 16400 PRINT "SAVE";  CHR$(34); PROTECTED.FILE$
  130. 16450 PRINT
  131. 16500 PRINT "CLS:LIST"
  132. 16550 LOCATE 1,1                                'Put cursor at col 1, row 1
  133. 16600 END               'Cursor drops to col 1, row 2 after Ok prompt
  134. 16650 '
  135. 16700 '=====>  Wait for user to press a key
  136. 16750 '
  137. 16800 PRINT
  138. 16850 PRINT "Press any key to start over."
  139. 16900 IK$ = ""
  140. 16950 WHILE IK$ = ""
  141. 17000   IK$ = INKEY$
  142. 17050 WEND
  143. 17100 RUN
  144. 17150 RETURN                                    'You will never get here
  145. 17200 '
  146. 17250 '=====>  Low warning buzz
  147. 17300 '
  148. 17350 FOR LOOP% = 1 TO 4
  149. 17400   SOUND  40, .5
  150. 17450   SOUND 200, .5
  151. 17500 NEXT
  152. 17550 RETURN
  153. 17600 '
  154. 17650 '=====>  Error handling
  155. 17700 '
  156. 17750 COLOR 15,0                                'Bright white on black
  157. 17800 MESG$ = ""
  158. 17850 IF ERR = 52 THEN MESG$ = "Invalid file specification.          "
  159. 17900 IF ERR = 53 THEN MESG$ = "File not found.                      "
  160. 17950 IF ERR = 61 THEN MESG$ = "Disk full.                           "
  161. 18000 IF ERR = 62 THEN MESG$ = "File is empty.                       "
  162. 18050 IF ERR = 64 THEN MESG$ = "Bad file name.                       "
  163. 18100 IF ERR = 67 THEN MESG$ = "Too many files.                      "
  164. 18150 IF ERR = 70 THEN MESG$ = "Disk write protected.                "
  165. 18200 IF ERR = 71 THEN MESG$ = "Disk not ready.                      "
  166. 18250 IF ERR = 72 THEN MESG$ = "Disk media error.                    "
  167. 18300 IF ERR = 75 THEN MESG$ = "Path/file access error.              "
  168. 18350 IF ERR = 76 THEN MESG$ = "Path not found.                      "
  169. 18400 GOSUB 17350                               'Low warning buzz
  170. 18450 IF MESG$ = "" THEN ON ERROR GOTO 0        'Unexpected error
  171. 18500 PRINT MESG$
  172. 18550 PRINT
  173. 18600 PRINT "Please correct the problem."
  174. 18650 GOSUB 16800                               'Press any key to continue
  175. 18700 'LISTING 2
  176. 18750 '
  177. 18800 'BUFFLOAD.SUB clears and optionally loads the keyboard buffer
  178. 18850 '
  179. 18900 '=====>  Load Keyboard Buffer
  180. 18950 '
  181. 19000 '----  If BUFF.1$ and BUFF.2$ both contain a string,
  182. 19050 '----  BUFF.1$ overrides BUFF.2$.
  183. 19100 '
  184. 19150 POKE 1050, PEEK(1052)                      'Clear the buffer
  185. 19200 DEF SEG = 0                                'Set segment to 0
  186. 19250 WHILE BUFF.1$ <> ""                        'Case 1 - normal codes
  187. 19300   POKE 1050, 30                            'Address of 1st byte in buffer
  188. 19350   BUFF.LEN% = LEN(LEFT$(BUFF.1$,15))       'Get truncated string size
  189. 19400   POKE 1052, 30 + 2 * BUFF.LEN%            'Addr of 1st byte after buffer
  190. 19450   FOR BUFF.LOOP% = 1 TO BUFF.LEN%          'Loop BUFF.LEN% times
  191. 19500     POKE 1052 + 2 * BUFF.LOOP%, ASC(MID$(BUFF.1$,BUFF.LOOP%,1))    'ASCII
  192. 19550   NEXT                                     'End loop
  193. 19600   BUFF.2$ = ""                             'Prevent case 2
  194. 19650   BUFF.1$ = ""                             'Set exit condition
  195. 19700 WEND                                       'End case 1
  196. 19750 '
  197. 19800 WHILE BUFF.2$ <> ""                        'Case 2 - extended codes
  198. 19850   POKE 1050, 30                            'Address of 1st byte in buffer
  199. 19900   BUF